from flask import Flask, Response
import nacos
# from DubboClientNew import DubboClientNew

SERVER_ADDRESSES = "10.19.95.31:8848"
NAMESPACE = "c6312e73-f0af-4604-9d31-2cac9ac09f33"
client = nacos.NacosClient(SERVER_ADDRESSES, namespace=NAMESPACE)
app = Flask(__name__)

# provider
@app.route('/python/<who>')
def provider(who):
    result = f'from {who} to python'
    return Response(result, mimetype='application/json')


# consumer 待续...
# @app.route('/python/java')
# def consumer():
#     dubboClient = DubboClientNew(SERVER_ADDRESSES, username='nacos', password='nacos')
#     result = dubboClient.callDubbo("xxx", "xxx")
#     return Response(result, mimetype='application/json')


if __name__ == "__main__":
    client.set_options()
    # register
    client.add_naming_instance("python-provider", "127.0.0.1", "8092", None, 1, None, False, False, False)  # 必须是永久实例，不然注册到注册中心后，监听不到心跳，我也还没搞清楚为啥
    app.run(port=8092)
